unit uTypes;

{$mode objfpc}{$H+}
{$modeswitch typehelpers}
{$modeswitch advancedrecords}


interface

uses
    Types, sysutils,
    Graphics;

type
    // Messages
    //########################################################
    TISMessageType = (
        msgGeneral,
        msgKeyboard,
        msgMouse,
        msgBrowser
        );

    TISMessageResult = (
        msrNone,        // Unknown result
        msrDone,        // Message processed (remove from the queue)
        msrPostponed,   // Message postponed (move to the end of the queue)
        msrRejected,    // Message rejected  (keep in the queue, ask other targets)
        msrContinue     // Processed and send it further
        );


    // Resize
    //########################################################

    TSizeSide = (
        ssNone, ssLeftTop, ssLeftBottom, ssRightTop, ssRightBottom,
        ssLeft, ssRight, ssTop, ssBottom);

    // Rendering engines
    //########################################################
    TRenderEngine = (reCEF, reHTMLView);

    // Classificators
    //########################################################
    TClassifVirtualNode = (cvnAll, cvnTrash);

    { TClassifItem }

    TClassifItem = class
    private
        FCaption: string;
        FDescription: string;
        FFontColor: TColor;
        FFontStyle: TFontStyles;
        FID: string;
        FParentID: string;
        FPictureName: string;
        procedure SetCaption(AValue: string);
        procedure SetDescription(AValue: string);
        procedure SetFontColor(AValue: TColor);
        procedure SetFontStyle(AValue: TFontStyles);
        procedure SetID(AValue: string);
        procedure SetParentID(AValue: string);
        procedure SetPictureName(AValue: string);
    protected
        procedure Init; virtual;
        procedure Done; virtual;


    public
        constructor Create; overload;
        constructor Create(const aID, aParentID, aCaption: string); overload;

        property ID: string read FID write SetID;
        property ParentID: string read FParentID write SetParentID;
        property Caption: string read FCaption write SetCaption;
        property Description: string read FDescription write SetDescription;
        property PictureName: string read FPictureName write SetPictureName;
        property FontColor: TColor read FFontColor write SetFontColor;
        property FontStyle: TFontStyles read FFontStyle write SetFontStyle;
    end;

    TClassifItemClass = class of TClassifItem;

    PClassifItemRec = ^TClassifItemRec;

    TClassifItemRec = record
        Data: TClassifItem;
    end;

    // Common list of something
    // #####################################################

    TISListStyle = (lsList, lsDetails, lsThumbnails);

    TISListItemState = (isNormal, isFocused, isSelected);

    TISList = class;

    TISListItem = class
    private
        FList: TISList;
    protected
    public
    end;

    { TISList }

    TISList = class
    private
        function GetCount: Integer;
        function GetItemByIndex(AIndex: Integer): TISListItem;
        procedure SetItemByIndex(AIndex: Integer; AValue: TISListItem);
    protected
    public
        property Count: Integer read GetCount;
        property ItemByIndex[AIndex: Integer]: TISListItem read GetItemByIndex write SetItemByIndex;
    end;

    // Type helpers
    // =====================================================

    { TPointHelper }

    TPointHelper = record helper for TPoint
        function AsString: string;

        procedure Init(const aX, aY: Integer); inline;
        procedure Move(const aDeltaX, aDeltaY: Integer); inline;
    end;

    { TRectHelper }

    TRectHelper = record helper for TRect
    private
        function GetHeight: Integer; inline;
        function GetWidth: Integer; inline;
        procedure SetHeight(AValue: Integer); inline;
        procedure SetWidth(AValue: Integer); inline;
    public
        function AsString: string;

        // Init rectangle using coordinates
        procedure InitCoord(const aLeft, aTop, aRight, aBottom: Integer);
        // Init rectangle using left upper corner and sizes
        procedure InitSize(const aLeft, aTop, aWidth, aHeight: Integer);
        // Move rectangle using deltas
        procedure Move(const aDeltaX, aDeltaY: Integer);
        // Move rectangle to the given left upper point
        procedure MoveToLT(const aX, aY: Integer);
        // Check is given point inside in the our rectangle
        function Contains(const aPoint: TPoint): Boolean;

        procedure CenterIn(const aRect: TRect); inline;

        property Width: Integer read GetWidth write SetWidth;
        property Height: Integer read GetHeight write SetHeight;
    end;

implementation

{ TISList }

function TISList.GetCount: Integer;
begin

end;

function TISList.GetItemByIndex(AIndex: Integer): TISListItem;
begin

end;

procedure TISList.SetItemByIndex(AIndex: Integer; AValue: TISListItem);
begin

end;

{ TRectHelper }

function TRectHelper.GetHeight: Integer;
begin
    Exit(Bottom - Top + 1);
end;

function TRectHelper.GetWidth: Integer;
begin
    Exit(Right - Left + 1)
end;

procedure TRectHelper.SetHeight(AValue: Integer);
begin
    Bottom := Top + AValue - 1;
end;

procedure TRectHelper.SetWidth(AValue: Integer);
begin
    Right := Left + AValue - 1;
end;

function TRectHelper.AsString: string;
begin
    Result :=
        'Left: ' + IntToStr(Left) + ' Top: ' + IntToStr(Top) +
        ' Right: ' + IntToStr(Right) + ' Bottom: ' + IntToStr(Bottom);
end;

procedure TRectHelper.InitCoord(const aLeft, aTop, aRight, aBottom: Integer);
begin
    Left := aLeft;
    Top := aTop;
    Right := aRight;
    Bottom := aBottom;
end;

procedure TRectHelper.InitSize(const aLeft, aTop, aWidth, aHeight: Integer);
begin
    Left := aLeft;
    Top := aTop;
    Right := aLeft + Pred(aWidth);
    Bottom := aTop + Pred(aHeight);
end;

procedure TRectHelper.Move(const aDeltaX, aDeltaY: Integer);
begin
    TopLeft.Move(aDeltaX, aDeltaY);
    BottomRight.Move(aDeltaX, aDeltaY);
end;

procedure TRectHelper.MoveToLT(const aX, aY: Integer);
begin
    Move(aX - Left, aY - Top);
end;

function TRectHelper.Contains(const aPoint: TPoint): Boolean;
begin
    Result := (aPoint.x >= Left) and (aPoint.x <= Right) and (aPoint.y >= Top) and (aPoint.y <= Bottom);
end;

procedure TRectHelper.CenterIn(const aRect: TRect);
begin

end;

{ TPointHelper }

function TPointHelper.AsString: string;
begin
    Result := 'X: ' + IntToStr(x) + ' Y: ' + IntToStr(y);
end;

procedure TPointHelper.Init(const aX, aY: Integer);
begin
    x := aX;
    y := aY;
end;

procedure TPointHelper.Move(const aDeltaX, aDeltaY: Integer);
begin
    x += aDeltaX;
    y += aDeltaY;
end;

{ TClassifItem }

procedure TClassifItem.SetCaption(AValue: string);
begin
    if FCaption = AValue then
        Exit;
    FCaption := AValue;
end;

procedure TClassifItem.SetDescription(AValue: string);
begin
    if FDescription = AValue then
        Exit;
    FDescription := AValue;
end;

procedure TClassifItem.SetFontColor(AValue: TColor);
begin
    if FFontColor = AValue then
        Exit;
    FFontColor := AValue;
end;

procedure TClassifItem.SetFontStyle(AValue: TFontStyles);
begin
    if FFontStyle = AValue then
        Exit;
    FFontStyle := AValue;
end;

procedure TClassifItem.SetID(AValue: string);
begin
    if FID = AValue then
        Exit;
    FID := AValue;
end;

procedure TClassifItem.SetParentID(AValue: string);
begin
    if FParentID = AValue then
        Exit;
    FParentID := AValue;
end;

procedure TClassifItem.SetPictureName(AValue: string);
begin
    if FPictureName = AValue then
        Exit;
    FPictureName := AValue;
end;

procedure TClassifItem.Init;
begin
    FFontColor := clWindowText;
    FFontStyle := [];
end;

procedure TClassifItem.Done;
begin

end;

constructor TClassifItem.Create;
begin
    Init;
end;

constructor TClassifItem.Create(const aID, aParentID, aCaption: string);
begin
    Init;

    FID := aID;
    FParentID := aParentID;
    FCaption := aCaption;
end;

end.
